export const actions = {
    getOrderList({},{type,id}) {
        return this.$api.order.getOrderList(type,id).then((res) => {
            if(res.data.status=="OK"){
                return Promise.resolve(res.data.data)
            }
            else{
                this.$router.push("/mainPage/error")
                return Promise.reject(new Error(res.data.msg))
            }
        },(error) => {
            this.$router.push("/mainPage/error")
            return Promise.reject(error)
        }).catch((error)=>{
            this.$router.push("/mainPage/error")
            return Promise.reject(error)
        })
    },
    updateOrder({},{shipAddress1,shipCity,shipState,shipZip,shipCountry,courier,shipToLastName,username,orderId,orderDate}){
        return this.$api.order.updateOrder(shipAddress1,shipCity,shipState,shipZip,shipCountry,courier,shipToLastName,username,orderId,orderDate).then((res)=>{
            if(res.data.status=="OK"){
                return Promise.resolve(res.data.msg)
            }
            else{
                this.$router.push("/mainPage/error")
                return Promise.reject(new Error(res.data.msg))
            }
        },(error) => {
            this.$router.push("/mainPage/error")
            return Promise.reject(error)
        }).catch((error)=>{
            this.$router.push("/mainPage/error")
            return Promise.reject(error)
        })
    },
    updateOrderStatus({},{orderId,status}){
        return this.$api.order.updateOrderStatus(orderId,status).then((res)=>{
            if(res.data.status=="OK"){
                return Promise.resolve(res.data.msg)
            }
            else
            {
                this.$router.push("/mainPage/error")
                return Promise.reject(new Error(res.data.msg))
            }
        },(error)=>{
            this.$router.push("/mainPage/error")
            return Promise.reject(error)
        }).catch((error)=>{
            this.$router.push("/mainPage/error")
            return Promise.reject(error)
        })
    },
}
